home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 1366 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.3 KB  |  43 lines

  1. Path: damage.usa1.net!news
  2. From: Kin Chan <firstian@usa1.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: Constructor of Matrix class
  5. Date: Wed, 10 Jan 1996 12:32:29 -0500
  6. Organization: USAinternet, Inc.
  7. Message-ID: <30F3F82D.3A9B@usa1.com>
  8. NNTP-Posting-Host: wmn1-142.usa1.com
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=us-ascii
  11. Content-Transfer-Encoding: 7bit
  12. X-Mailer: Mozilla 2.0b4 (Macintosh; I; PPC)
  13.  
  14. Hi,
  15.     I wrote a simple matrix class for my own use, with all the 
  16. arithmetic operators overloaded. I have a question about writing a 
  17. constructor. The class declaration looks something like this
  18.  
  19. class matrix {
  20. public:
  21.     matrix(int row=0, int col=0);
  22.     ~matrix
  23. ...
  24. private:
  25.     int    row,col;
  26.     double    *elemptr
  27. };
  28.  
  29. Based on the row and col given to the constructor, the constructor 
  30. will allocate the correct amount of memory to elemptr. However, I 
  31. have not been able to come up with a way to initialize all the 
  32. elements of the matrix during the constructor call. The only thing 
  33. that I can do now is to call the operator() that I overloaded to 
  34. access the elements one by one, which is very cumbersome for, say, a 
  35. 9*9 matrix, which I use all the time. Basically, I wish I can do 
  36. something like
  37.  
  38. matrix    M(2,2,{1.0,2.0,3.0,4.0});
  39.  
  40. Like in MapleV. How can I simulate that?
  41.  
  42. Thanks
  43.